/* 
 * File:   tftp.h
 * Author: gaurav
 *
 * Created on 2 January, 2011, 1:47 PM
 */

#ifndef TFTP_H
#define	TFTP_H

# include <stdlib.h>
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <fcntl.h>
# include <signal.h>
# include <errno.h>
# include <arpa/inet.h>
# include <netinet/in.h>
# include <sys/time.h>
# include <sys/wait.h>
# include <sys/socket.h>
# include <sys/types.h>
# include <sys/stat.h>
# include <sys/types.h>
# include <sys/select.h>

# define RRQ 1
# define WRQ 2
# define DATA 3
# define ACK 4
# define ERROR 5


# define File_not_found 1
# define Access_violation 2
# define Disk_full_or_allocation_exceeded 3
# define Illegal_TFTP_operation 4
# define Unknown_transfer_ID 5
# define File_already_exists 6
# define No_such_user 7


# define TIMEOUT 15 //in seconds
# define MAX_ACK_RETRIES 15
# define MAX_TIMEOUT_RETRIES 5


# define DIR "/home/puper/share/jonson-tftp"
# define _GNU_SOURCE


typedef struct _RRQ_WRQ_PACKET
{
    short opcode;
    char filename[80];
    char mode[10];
}REQ_PKT;

typedef struct _DATA_PACKET
{
    short opcode;
    short block_no;
    char data[512];
}DATA_PKT;

typedef struct _ACK_PACKET
{
    short opcode;
    short block_no;
}ACK_PKT;

typedef struct _ERROR_PACKET
{
    short opcode;
    short ErrorCode;
    char errmsg[512];
}ERR_PKT;


#define print_socket( x )  printf("%s:%d  %s:%d  \n", __func__, __LINE__,inet_ntoa(x.sin_addr),ntohs(x.sin_port));
#define print_debug  printf("%s:%d \n", __func__, __LINE__);

#define UTFTP_PATH      "/var"
#define SYSINFO_FILE    "caminfo"
#define SETIP_FILE      "setip"  //setip@Admin@Admin&mac=08-00-27-95-CA-96&ip=192.168.127.50&mask=255.255.0.0&gw=192.168.1.254
#define UID_FILE        "uid"
#define UPGRADE_FILE    "upgrade" //write command: upgrade@Admin@Admin&mac=08-00-27-95-CA-96


typedef struct _DATA_CAMINFO
{
    struct sockaddr_in cl_addr;
    char *file;
    int s_l;
}DATA_CAMINF;

void *thd_caminfo( void *ptr );





#endif	/* TFTP_H */

